package DCSource.Streams;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.ArrayList;

public class SplittOutputStream extends OutputStream{
	private ArrayList<OutputStream> list = new ArrayList<OutputStream>();
	private ArrayList<PrintStream> list2 = new ArrayList<PrintStream>();
	public SplittOutputStream(){}
	public SplittOutputStream(OutputStream... a){
		for (OutputStream b : a){
			list.add(b);
		}
	}
	public SplittOutputStream(PrintStream... a){
		for (PrintStream b : a){
			list2.add(b);
		}
	}
	public void add(OutputStream... a){
		for (OutputStream b : a){
			list.add(b);
		}
	}
	public void remove(OutputStream... a){
		for (OutputStream b : a){
			list.remove(b);
		}
	}
	public void add(PrintStream... a){
		for (PrintStream b : a){
			list2.add(b);
		}
	}
	public void remove(PrintStream... a){
		for (PrintStream b : a){
			list2.remove(b);
		}
	}
	public OutputStream[] getOutputList(){
		return list.toArray(new OutputStream[list.size()]);
	}
	public PrintStream[] getPrintList(){
		return list2.toArray(new PrintStream[list.size()]);
	}
	public void clear(){
		list.clear();
		list2.clear();
	}
	public void write(int a) throws IOException{
		for (OutputStream b : list){
			b.write(a);
		}
		for (PrintStream c : list2){
			c.write(a);
		}
	}
	public void write(byte[] a) throws IOException{
		for (OutputStream b : list){
			b.write(a);
		}
		for (PrintStream c : list2){
			c.write(a);
		}
	}
	public void write(byte[] a, int off, int len) throws IOException{
		for (OutputStream b : list){
			b.write(a,off,len);
		}
		for (PrintStream c : list2){
			c.write(a,off,len);
		}
	}
	public void flush() throws IOException{
		for (OutputStream b : list){
			b.flush();
		}
		for (PrintStream c : list2){
			c.flush();
		}
	}
	public void close() throws IOException{
		for (OutputStream b : list){
			b.flush();
			b.close();
		}
		for (PrintStream c : list2){
			c.flush();
			c.close();
		}
		list.clear();
	}
}
